<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
 <%
 String ctxPath = request.getContextPath();
    String fileType =null;
     String maxImages = request.getParameter("maxImages");
    if(fileType==null)
    {
     	fileType="jpg";
    }
    if(maxImages==null)
    {
     	maxImages="1";
    }
%>
<object classid = "clsid:5220cb21-c88d-11cf-b347-00aa00a28331" VIEWASTEXT>
	<param name="LPKPath" value="<%= request.getContextPath()%>/cabs/DynamicWebTwain.lpk" />
</object>
<table border="0" align="left" width="150" style="width:85%;height:100;">
 <tr>
   <td align="center" bgcolor="gray"  width="130"> 
     <object classid="clsid:E7DA7F8D-27AB-4EE9-8FC0-3FEC9ECFE758" id="webTwain" height="100" width="130" bgcolor="gray"
	CodeBase = "<%= ctxPath%>/cabs/DynamicWebTWAIN.cab#version=6.1">
		<param name="_cx" value="847" />
		<param name="_cy" value="847" />
		<param name="JpgQuality" value="80" />
		<param name="Manufacturer" value="Dynamsoft Corporation" />
		<param name="ProductFamily" value="Dynamic Web TWAIN" />
		<param name="ProductName" value="Dynamic Web TWAIN" />
		<param name="VersionInfo" value="Dynamic Web TWAIN 6.1" />
		<param name="TransferMode" value="0" />
		<param name="BorderStyle" value="0" />
		<param name="FTPUserName" value="" />
		<param name="FTPPassword" value="" />
		<param name="FTPPort" value="21" />
		<param name="HTTPUserName" value="" />
		<param name="HTTPPassword" value="" />
		<param name="HTTPPort" value="80" />
		<param name="ProxyServer" value="" />
		<param name="IfDisableSourceAfterAcquire" value="0" />
		<param name="IfShowUI" value="1" />
		<param name="IfModalUI" value="1" />
		<param name="IfTiffMultiPage" value="0" />
		<param name="IfThrowException" value="0" />
		<param name="MaxImagesInBuffer" value="<%=maxImages %>" />
		<param name="TIFFCompressionType" value="0" />
	</object>
   </td>
  
         
   <td>
     <table border="0" >
       <tr>
         <td style="width:60%;text-align: center">
           <input type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role=button type=button jQuery191036113586339611503="24" value="开始扫描" onclick="scan();" id="scanbutton">
           <input type="button"   value="本地上传" onclick="uploadshow();" id="scanbutton2"  class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role=button type=button jQuery191036113586339611503="24">
         </td>
       </tr>
     </table>
   </td>
 </tr>
 <tr> <td >
 <select id="source" >
         	  <option value="">请选择...</option>
         	</select>
         	</td></tr>
</table> <script>
function setButtonDisable(button,value){
	button.disabled=value;
	button.style.filter=value?"Gray":"";
}

function refreshImageIndex(){
}
var initedSvrConf=null;
function getDomainConfig()
{
	if(initedSvrConf!=null){
		return initedSvrConf;
	}
	var currentUrl=	window.location.href;
	var conf={};
	var domainurl="";
	var sport="80";
	if(currentUrl.indexOf("www")==0){
		domainurl=currentUrl.split("/")[0];
	}else if(currentUrl.indexOf("http")==0){
		var urlsec= currentUrl.split("//")[1];
		domainurl=urlsec.split("/")[0];
	}
	if(domainurl.indexOf(":")!=-1){
		var dom = domainurl.split(":");
		conf = {s_domain:dom[0],s_port:dom[1]}; 	
	}else{
		conf = {s_domain:domainurl,s_port:sport};
	}
	initedSvrConf=conf;
	return conf;
}
function upload(){
	if(colorForm.webTwain.HowManyImagesInBuffer<1)
		{
			return ;
		}
	
	colorForm.webTwain.HTTPPort=getDomainConfig().s_port;
  var isSuccess=false;
 var s_domain = getDomainConfig().s_domain;
 
 if(colorForm.webTwain.HowManyImagesInBuffer==1){
	 setButtonDisable(document.getElementById("scanbutton"),true);
    isSuccess=colorForm.webTwain.HTTPUploadThroughPost(s_domain,0,"<%= ctxPath%>/GetScanFile;jsessionid=<%=request.getSession().getId() %>","temp_compare.jpg");
 }
  if(isSuccess){
	  scanquery();
  }else{
   		alert("上传失败，请联系管理员");
  }
}
var retryTimes=0;
function initscan(){
  try{
	  colorForm.webTwain.Zoom=800;
	  colorForm.webTwain.SetViewMode(-1,-1);
    for(var i=0;i<colorForm.webTwain.SourceCount;i++){
      var sourceName=colorForm.webTwain.SourceNameItems(i);
      colorForm.source.options.add(new Option(sourceName,String(i)));
    }
    if(colorForm.webTwain.SourceCount>0){
    	colorForm.source.selectedIndex=1;
    }
    refreshImageIndex();
  }catch(e){
    retryTimes++;
 	if(retryTimes>3)
 	  throw new Error("初始化失败");
 	else
 	  window.setTimeout(initscan,1000);
  }
}
if (window.attachEvent) {  
    window.attachEvent("onload", initscan);  
} else if (window.addEventListener) {  
    window.addEventListener("load", initscan, false);    
}   
function scan(){
  if(colorForm.source.selectedIndex==0){
    alert("请选择扫描仪");
    return;
  }
  setButtonDisable(document.getElementById("scanbutton"),true);
  colorForm.webTwain.CloseSource();
  colorForm.webTwain.OpenSource();
  colorForm.webTwain.IfShowUI =false;
  colorForm.webTwain.IfDisableSourceAfterAcquire = true;
  colorForm.webTwain.SelectSourceByIndex(Number(colorForm.source.value));  
  colorForm.webTwain.AcquireImage();
}

function setButtonsStatus(){
	setButtonDisable(document.getElementById("scanbutton"),false);
	document.getElementById("queryImage").style.filter = '';
	
}
</script>
<script language="javascript" for="webTwain" event="OnPostTransfer">
	setButtonsStatus();
	refreshImageIndex();
</script>
 
